from conn import mysql_conn as mc,kb
import globe
MC = mc.MysqlConn()


# 获取今日新闻
def get_totay_news():
    news_list = MC.search_news()
    return news_list

# 获取新闻详情
def get_news_by_id(news_id):
    news = MC.search_news_by_id(news_id)
    if news['is_protected']:
        news['content_zh'] = "访问原链接获取更多详情"
    entitys = MC.search_entitys(news['entitys'])
    for entity in entitys:
        entity['type']=globe.entity_type[entity['type']]
    news['entitys']= entitys
    return news

# 搜索新闻
def search_news(query):
    urls = kb.search(query)
    return MC.search_news_by_urls(urls)

if __name__ == '__main__':
    print(get_news_by_id('b7b08671-c596-425f-825b-6df4a3258b3d'))